﻿<?php


$obj=new mysql($config);
$id=$_GET['id'];
$sql="select `goodsattr`.*,`attr`.attr_name from `goodsattr` inner join `attr` on `goodsattr`.`attr_id`=`attr`.id where `goodsattr`.`goods_id`=$id and `attr`.`attr_type`=0";
$date=$obj->getCondition($sql);
$arr=array();
foreach ($date as $k => $v) {
$arr[$v['attr_id']][]=$v;
}



if(!empty($_POST)){
	$arr=array();
    $id=$_POST['id'];
 foreach ($_POST['number'] as $k => $v) {
 	foreach ($_POST['goodsattr'] as $k1 => $v1) {
 		   $arr[$k][]=$v1[$k];

 	}
 }

 foreach ($arr as $k => $v) {
 	if(is_array($v)){
        $arr[$k]=implode(',',$v);
 	}
 }

 foreach ($arr as $k => $v) {
 	$obj->insert(array('goods_id'=>$id,'goodsattr_id'=>$v,'number'=>$_POST['number'][$k]),'goodsnumber');
 }
   echo '<script>alert("添加成功");location.href="index.php?c=goods&a=list&mod=admin";</script>';
 print_r($arr);
 print_r($_POST);
}




require_once (VIEW_PATH.'admin/layout.html');